package com.example.weather.adapter

import android.content.Context
import android.view.ViewGroup
import com.example.weather.model.ForecastItem
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.example.weather.R

class WeatherForecastAdapter: BaseQuickAdapter<ForecastItem, QuickViewHolder>() {

    var mContext: Context? = null

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        mContext = context
        return QuickViewHolder(R.layout.item_weather_forecast, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: ForecastItem?) {
        holder.run {
            setText(R.id.tv_day_of_week, item?.dayOfWeek)
            setText(R.id.tv_date, item?.date)
            setImageResource(R.id.iv_weather_icon, item?.image ?: R.drawable.img_cloudy)
            setText(R.id.temperature, item?.temperature)
            setText(R.id.tv_rain_probability, item?.airQuality)
        }
    }
}